<template>
  <el-main style="height: 100%;">
        <div style="width: 700px;padding: 10px 10px; display: flex;">
          <el-input v-model="name" placeholder="请输入名称" suffix-icon="el-icon-search" style="margin-right: 10px;"></el-input>
          <el-input v-model="description" placeholder="请输入描述" suffix-icon="el-icon-message" style="margin-right: 10px;"></el-input>
          <el-button @click="search(this)">搜索</el-button>
          <el-button type="warning" @click="reset(this)">重置</el-button>
        </div>
         
        <div style="width: 700px;padding: 10px 10px; display: flex;">
          <el-button type="primary" @click="handleAddAction">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
        </div>
        <el-table
            :data="tableData"
            style="width: 100%;margin-bottom: 20px;"
            row-key="id"
            border
            
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column prop="id" label="ID"></el-table-column>
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column prop="path" label="路径"></el-table-column>
            <el-table-column prop="icon" label="图标"></el-table-column>
            <el-table-column prop="description" label="描述"></el-table-column>
            <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" round @click="handleAddChild(scope.row.id)">增加子类菜单 <i class="el-icon-circle-plus-outline"></i></el-button>
              <el-button type="warning" round >修改 <i class="el-icon-star-on"></i></el-button>
            </template>
          </el-table-column>
        </el-table>
    <!-- 表单弹窗 -->
<el-dialog title="信息增加/修改" :visible.sync="dialogFormVisible" size="small">
  <el-form :model="form" label-width="70px">
    <el-form-item label="名称" >
      <el-input v-model="form.name" auto-complete="off"></el-input>
    </el-form-item>
    <el-form-item label="路径" >
      <el-input v-model="form.path" auto-complete="off"></el-input>
    </el-form-item>
    <el-form-item label="图标" >
      <el-input v-model="form.icon" auto-complete="off"></el-input>
    </el-form-item>
    <el-form-item label="描述" >
      <el-input v-model="form.description" auto-complete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleAdd">确 定</el-button>
  </div>
</el-dialog>

  </el-main>
</template>

<script>
import {loadMyMessage,addMenu} from "@/api/menu"
export default {
    data() {
    return {
      tableData: null,
      name:"",
      description:"",
      dialogFormVisible:false,
      form:{},
    }
  },created(){
    this.loadMessage()
  },
  methods:{
    handleAction(){
        this.dialogFormVisible=false
    },
    async loadMessage(){
        const res=await loadMyMessage()
        this.tableData=res.data.result
        this.name=""
        this.description=""
    },
    search(){
        this.loadMessage()
    },
    reset(){
        this.name=""
        this.description=""
    },
    async handleAdd(){
        //增加菜单
        const res=await addMenu(this.form);
        if(res.code===200){
            this.$message.success("新增成功")
            this.dialogFormVisible=false
            this.form={}
            this.loadMessage()
        }
    },
    handleAddAction(){
        this.dialogFormVisible=true
    },
    handleAddChild(pid){
        this.handleAddAction()
        this.form.pid=pid
    }
  }

}
</script>

<style>

</style>